package com.hl.controller;

import com.hl.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    // 获取验证码
    //@requestParam参数中获取值   可以接收键值对格式的传值
    //接收json格式的值需要加@Requestbody     post put
    @PostMapping("/getCode")
    public String getCode( String phoneNumber) {
        // 调用服务生成验证码并返回
        return verificationCodeService.generateAndSaveCode(phoneNumber);
    }

    // 验证验证码
    @PostMapping("/verifyCode")
    public boolean verifyCode(@RequestParam String phoneNumber, @RequestParam String code) {
        // 调用服务验证验证码
        return verificationCodeService.verifyCode(phoneNumber, code);
    }
}